import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/Layout'

Vue.use(VueRouter)

export const constantRoutes = [
  {
    path: '/login',
    name: 'Login',
    component: (resolve) => require(['@/views/login/index'], resolve)
  },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    name: 'Layout',
    children: [
      {
        id: 1,
        path: 'dashboard',
        component: (resolve) => require(['@/views/dashboard/index'], resolve),
        title: '首页',
        icon: 'agriculture',
        visible: '0',
      }
    ]
  }
]

// export const ansyRouters= [
//   {
//     path: '/manage',
//     component: Layout,
//     redirect: '/manage/user',
//     name: 'Manage',
//     meta: { title: '管理', icon: 'manage'},
//     children: [
//       {
//         path: 'user',
//         component: () => import('@/views/manage/user'),
//         name: 'User',
//         meta: { title: '用户管理'}
//       },
//       {
//         path: 'role',
//         component: () => import('@/views/manage/role'),
//         name: 'Role',
//         meta: { title: '角色管理'}
//       },
//       {
//         path: 'menu',
//         component: () => import('@/views/manage/menu'),
//         name: 'Menu',
//         meta: { title: '菜单管理'}
//       }
//     ]
//   }
// ]

const initRouter = () => new VueRouter({
  // mode: 'history', // require service support
  // scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
const router = initRouter()

export function restRourers(){
  const newRouter = initRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
